<template>


        <div style="height:100%">
                <div style="padding:30px;">
                        <el-button type="primary">
                                <router-link to="/admin/adlistadd" tag="span">广告添加</router-link>
                        </el-button>
                        <br>
                        <br>
 

                        <el-table
                                :data="tableData"
                                border
                                style="width: 100%">
                                <el-table-column
                                        fixed
                                        prop="http"
                                        label="地址"
                                        width="350">
                                </el-table-column>
                                        <el-table-column

                                                prop="type"
                                                label="分类"
                                                width="350">
                                        </el-table-column>

                                <el-table-column

                                        label="图片"
                                        width="300">
                                        <template slot-scope="scope">
                                                <div>
                                                        <img style="height:50px" :src="scope.row.url" alt="">
                                                </div>
                                        </template>
                                </el-table-column>

                                <el-table-column
                                        fixed="right"
                                        label="操作"
                                        width="100">
                                        <template slot-scope="scope">
                                                <el-button @click="handleClick(scope.row)" type="text" size="small">删除</el-button>
                                                <router-link :to="'/admin/adsave/'+scope.row.id">修改</router-link>
                                        </template>
                                </el-table-column>
                        </el-table>

                        <br>
                        <el-pagination
                                background
                                :page-size="30"
                                layout="prev, pager, next"
                                :current-page="currentPage"
                                @current-change="handleCurrentChange"
                                :total="total">
                        </el-pagination>
                </div>
        </div>

</template>

<script>
    export default {
        mounted() {

            axios.post('/api/adlist').then(rew=>{
                this.tableData = rew.data.data
            })
        },
        methods: {
            onSubmit() {
                console.log(this.formInline);
                //搜索对应题目
                //章节分类
                axios.post('/api/SubOneSearch',this.formInline).then(rew=>{
                    //表格的数据赋值
                    this.tableData = rew.data.data
                    //页码数据赋值
                    this.total = rew.data.total
                })
            },
            handleClick(row) {
                this.$confirm('是否删除该题目?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.post('/api/delad', row).then(rew => {
                        var index = this.tableData.indexOf(row)
                        this.tableData.splice(index, 1);
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            handleCurrentChange(currentPage) {
                let  page={
                    page: currentPage
                }
                axios.post('subone/getlist', page).then(rew => {
                    this.tableData = rew.data.data
                    this.total = rew.data.total
                })
            },
            hand(val, id) {
                let data = {
                    is_zy: val,
                    id: id
                }
                axios.post('/zy', data).then(rew => {
                })
            },
            ycthand(val, id) {
                let data = {
                    is_yct: val,
                    id: id
                }
                axios.post('/yc', data).then(rew => {

                })
            }
        },
        data() {
            return {
                chapters:'',
                tableData: [],
                currentPage: 1,
                total:0,
                formInline: {
                    title: '',
                    chapters_id: ''
                }
            }
        }
    }
</script>
<style scoped>

</style>